<%@ page language="java" pageEncoding="utf-8"%>
<%@ include file="/commons/taglibs.jsp"%>
<html>
<head>
<title>配置管理</title>
<%@ include file="/commons/meta.jsp" %>
<%@ include file="/commons/header.jsp" %>
<%@ include file="/extjs/jsps/importExt.jsp" %>
<%@ include file="/extjs/jsps/importEasyExt.jsp" %>
<script language="javascript" type="text/javascript">
Ext.onReady(function() {
	
	var store = new Ext.data.JsonStore({
		autoDestroy: true,
		autoLoad: true,
		remoteSort: true,
		url: '${ctx}/keyValue!listJSON.action',
	   	root: 'records',
	   	paramNames: {
	   	    start: 'page.start',
	   	    limit: 'page.limit',
	   	    sort: 'page.sort',
	   	    dir: 'page.dir'
	   	},
		fields: [
	        {name: 'id',mapping: 'id',type: 'string'},
	        {name: 'name',mapping: 'name',type: 'string'},
	        {name: 'key',mapping: 'key',type: 'string'},
	        {name: 'value',mapping: 'value',type: 'string'},
	        {name: 'createUser',mapping: 'createUser',type: 'string'},
	        {name: 'createUserName',mapping: 'createUserName',type: 'string'},
	        {name: 'createTime',mapping: 'createTime',type: 'string'},
	        {name: 'updateUser',mapping: 'updateUser',type: 'string'},
	        {name: 'updateUserName',mapping: 'updateUserName',type: 'string'},
	        {name: 'updateTime',mapping: 'updateTime',type: 'string'}
		]
	});

	var sm = new Ext.grid.CheckboxSelectionModel({
		singleSelect: false
	});

	var cm = new Ext.grid.ColumnModel({
		defaults: {
			align: 'center',
			sortable: true
		},
		columns: [
			new Ext.grid.RowNumberer(), 
			sm,
			{header: '名称',dataIndex: 'name',width: 18},
			{header: '键',dataIndex: 'key',width: 17},
			{header: '值',dataIndex: 'value',width: 15},
			{header: '创建者',dataIndex: 'createUser',width: 10,
				renderer: function(value,metaData,record,rowIndex,colIndex,store){
					return record.get('createUserName');
				}
			},
			{header: '创建时间',dataIndex: 'createTime',width: 15},
			{header: '更新者',dataIndex: 'updateUser',width: 10,
				renderer: function(value,metaData,record,rowIndex,colIndex,store){
					return record.get('updateUserName');
				}
			},
			{header: '更新时间',dataIndex: 'updateTime',width: 15}
		]
	});


	var toolbarItem = ['-',{
		xtype: 'button',
		text: '新建',
		iconCls: "addBtn",
		handler: function() {
			var url="${ctx}/keyValue!input.action?winId=winInsertKeyValue&U="+(new Date().getTime());
			windowOpen(url,'winInsertKeyValue','新增键值对',255,355,'','',{
				onClose: function(scope){
					var obj=scope.returnValue;
					if(obj){
						store.reload();
					}
				}
			});
		}
	},'-',{
		xtype: 'button',
		text: '编辑',
		iconCls: "editBtn",
		handler: function() {
			if (sm.getCount()!=1) {
				Common.showErrorMsg('必须且仅能选择一条记录！');
				return;
			}
			var paraUrl="&id="+sm.getSelections()[0].get("id");
			var url="${ctx}/keyValue!input.action?winId=winUpdateKeyValue&U="+(new Date().getTime())+paraUrl;
			windowOpen(url,'winUpdateKeyValue','更新键值对',255,355,'','',{
				onClose: function(scope){
					var obj=scope.returnValue;
					if(obj){
						store.reload();
					}
				}
			});
		}
	},'-',{
		xtype: 'button',
		text: '删除',
		iconCls: "deleteBtn",
		handler: function() {
			if (sm.getCount()==0) {
				Common.showErrorMsg('请至少选择一条记录！');
				return false;
			}
			Ext.Msg.confirm("","确认删除？",function(e) {
				if (e=='no') {
					return;
				}
				Common.ajaxRequest('${ctx}/keyValue!deleteJSON.action',{
					ids: Common.getSelectedProperties(sm,'id')
				},function(success) {
					if(success) {
						store.reload();
					}
				});
			});
		}
	}];
				
	var gridPanel = new Ext.grid.EditorGridPanel({
		style: 'text-align: left',
		border: true,
		stripeRows: true,// 斑马线效果
		loadMask: {
			msg: '加载数据中, 请稍侯... ...'
		},
		trackMouseOver: true,
		store: store,
		autoExpandColumn: 'name',
		cm: cm,
		sm: sm,
		clicksToEdit: 1,// 单击编辑
		viewConfig: {
			scrollOffset: 20,// 滑动条宽度，默认是20
			forceFit: true
		},
		tbar: Common.pageingToolBar(new EasyExt.widgets.PageSizePlugin(),store, toolbarItem)
	});
	
	var viewport = new Ext.Viewport({
		layout: 'fit',
		border: false,
		items: [gridPanel]
	});
});
</script>
</head>

<body>
</body>
</html>